package niuke;

/**
 * description:
 * author:张腾
 * date:2021-06-29
 */

/**
 * 给你一个非空模板串S，一个文本串T，问S在T中出现了多少次
 */
public class NC149 {
    public int kmp (String S, String T) {
        // write code here
        int sL = S.length();
        int tL = T.length();
        if (tL<sL) return -1;
        int ans = 0;
        for (int i = 0; i <= tL - sL; i++) {
            String tmp = T.substring(i, sL+i);
            if (tmp.equals(S)) ans++;
        }
        return ans;
    }
}
